package com.whosly.mysql.protocol.constant;

/**
 * 连接的常量类定义
 *
 * @author 风杨
 * @date 2023/07/21 下午4:03
 * @see <a href="yueny09@163.com">mailTo: yueny09@163.com</a>
 */
public class ConnKeyConstant {
    /**
     * Session管理
     */
    private static final String SESSION_DOMAIN = "RushDB:MANAGER:SESSION:";

    /**
     * session 管理， {} 为cid
     */
    private static final String SESSION = SESSION_DOMAIN + "CID:%s";

    public static final String getSessionKey(Long cid){
        return String.format(SESSION, cid);
    }


    /**
     * 连接管理
     */
    private static final String PID_DOMAIN = SESSION_DOMAIN;

    /**
     * pid 与 cid 的映射关系, PID为租户维度
     *
     * {1} 为 tenantId, {2} 为 pid
     */
    public static final String PID_HASH_FOR = PID_DOMAIN + "TENANTID:%s:PID:HASH:%s";

    /**
     * 活动中的 cid 与 ConnTraceInfo 的映射关系
     * 为方便扫描，key中ID后置
     *
     * {1} 为 cid
     */
    public static final String CID_ACTIVITY = PID_DOMAIN + "CID:ACTIVITY:%s";

    /**
     * 活动中的pid 与 PidInfo 的映射关系
     * 为方便扫描，key中ID后置
     *
     * {1} 为 cid, {2} 为 pid
     */
    public static final String PID_ACTIVITY = PID_DOMAIN + "CID:ACTIVITY:%s:%s";

    /**
     * 结束的pid 与 PidInfo 的映射关系
     * 为方便扫描，key中ID后置
     * {1} 为 cid, {2} 为 pid
     */
    public static final String PID_FINISH = PID_DOMAIN + "CID:FINISH:%s:%s";

    public static final String getPidHashFor(Long tenantId, Long pid) {
        return String.format(PID_HASH_FOR, tenantId, pid);
    }

    public static final String getCidActivity(Long cid) {
        return String.format(CID_ACTIVITY, cid);
    }

    public static final String getPidActivity(Long cid, Long pid) {
        return String.format(PID_ACTIVITY, cid, pid);
    }

    public static final String getPidFinish(Long cid, Long pid) {
        return String.format(PID_FINISH, cid, pid);
    }

}
